/**
 * 管理后台首页相关JS
 * author: zhanghua 2015-9-9
 */
$(function(){
	$('#btnPublish').click(function () {

		var title = $("#title").val();
		var titlelen = $('.count').text();
		var content = $("#setContent").val();
		var thumb = 'https://r1.ykimg.com/05FF0D01579DCC1E642025428E5E1AB8';
		var abstract = $("#abstract").val();
		var label1 = $(".labels").eq(0).attr('label');
		var label2 = $(".labels").eq(1).attr('label');
		var label3 = $(".labels").eq(2).attr('label');
		var columnIds = label1;
		if(label2 != null && label2 !=null){
			columnIds = columnIds+','+ label2;
		}
		if(label3 != null && label3 !=null){
			columnIds = columnIds+','+ label3;
		}

		var status = $(this).attr('status');

		if(title == null || title == ''){
			alert('资讯标题不能为空')
			return false;
		}
		if(titlelen>30){
			alert('资讯标题不能大于30字')
		}

		if(thumb == null || thumb == ''){
			alert('资讯封面不能为空')
			return false;
		}
		if(columnIds == null || columnIds == '' ){
			alert('相关频道不能为空')
			return false;
		}


		var data = {
			"title" :title,
			"content" : content,
			"thumb" : thumb,
			"abstract" : abstract,
			"columnIds" : columnIds,
			"status" :status,
		};
		var postUrl = $('#postSaveArticleUrl').val()
		var jumpUrl = $('#jumpUrl').val();

		post_json(postUrl, data ,function(res){
			switch(res.status){
				case 1:
					location.href = jumpUrl;
					break;
				case 0:
					alert(res.msg);
					break;
			}
		});
		return false;
	});
});


